import java.util.*;
class MyComparator implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2-o1;
    }
}
public class Main {

    public static void main(String[] args) {
        BinaryTree binaryTree = new BinaryTree();
        TreeNode root = binaryTree.create();
        pathSum(root,22);
    }
    static List<List<Integer>> ret = new ArrayList<>();
    public static List<List<Integer>> pathSum(TreeNode root, int targetSum) {

        if(root == null) return ret;
        List<Integer> list = new ArrayList<>();
        sum(root,targetSum,list);
        return ret;

    }
    public static void sum(TreeNode root, int targetSum, List<Integer> list) {
        list.add(root.val);
        if(root.right == null && root.left == null){// 到叶子结点，看是否符合条件，返回
            if(targetSum == root.val){
                ret.add(list);
            }
            return;
        }
        if(root.left != null) {
            sum(root.left,targetSum-root.val,list);
            list.remove(list.size()-1);
        }
        if(root.right != null) {
            sum(root.right,targetSum-root.val,list);
            list.remove(list.size()-1);
        }
    }



//    public static void main5(String[] args) {
//        BinaryTree binaryTree = new BinaryTree();
//        TreeNode root = binaryTree.create();
//        System.out.println(binaryTreePaths(root));
//        System.out.println();
//    }
//    static List<String> ret = new ArrayList<>();
//    public static List<String> binaryTreePaths(TreeNode root) {
//
//        if(root == null) return ret;
//        dfs(root,"");
//        return ret;
//    }
//    public static void dfs(TreeNode root,String str) {
//        if (root == null) return;
//        str += root.val;
//
//        if (root.left == null && root.right == null) {
//            ret.add(str);
//            return;
//        }
//        if (root.left != null) {
//            dfs(root.left,str+"->");
//        }
//        if (root.right != null) {
//            dfs(root.right,str+"->");
//        }
//    }

    public static void main4(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer num = scanner.nextInt();

        Integer[] nums = new Integer[num+1];
        for (int i = 1; i <= num; i++) {
            nums[i] = i;
        }

        int count = scanner.nextInt();
        int[][] counts = new int[count][2];
        for (int i = 0; i < count; i++) {
            counts[i][0] = scanner.nextInt();// 排序方式
            counts[i][1] = scanner.nextInt();
        }
        int max = 0;
        int min = nums.length;
        for (int i = 0; i < count; ) {
            if (counts[i][0] == 0) {
                while (i < count && counts[i][0] == 0) {
                    max = Math.max(max,counts[i][1]);
                    i++;
                }
                Arrays.sort(nums, 1, max + 1, new MyComparator());
                max = 0;
            }else {
                while (i < count && counts[i][0] == 1) {
                    min = Math.min(min,counts[i][1]);
                    i++;
                }
                Arrays.sort(nums,min,nums.length);
                min = nums.length;
            }
        }
        for (int i = 1; i <= num; i++) {
            System.out.print(nums[i] + " ");
        }
    }


//    public static long ret;
//    public static void main3(String[] args) {
//        Scanner scanner = new Scanner(System.in);
//        String str = scanner.nextLine();
//        char[] chars = str.toCharArray();
//        int left = 0;
//        int right = 0;
//        for (int i = 0; i < chars.length; i++) {
//            if (chars[i] == '(') left++;
//            if (chars[i] == ')') right++;
//        }
//        if (left > right) {
//            dfsLeft(chars,0,0,0,left-right);
//        }else {
//            dfsRight(chars,0,0,0,right - left);
//        }
//        System.out.println(ret);
//    }
//    public static void dfsLeft(char[] chars,int index,int left,int right,int rightMore) {
//        if(index == chars.length && rightMore == 0 && left == right) {
//            ret++;
//            return;
//        }
//        if (right > left) {
//            return;
//        }
//        if (left > right) {
//            dfsLeft(chars,index,left,right+1,rightMore-1);
//        }
//        char c = chars[index++];
//        if (c == '(') {
//            dfsLeft(chars, index, left+1, right, rightMore);
//        }
//    }
    public static void dfsRight(char[] chars,int index,int left,int right,int leftMOre) {
//        if(index == chars.length && leftMOre == 0 && rightMore == 0) {
//            ret++;
//            return;
//        }
//        if (right > left && leftMOre <= 0) {
//            return;
//        }
//        if (left > right && rightMore <= 0) {
//            return;
//        }
//        index++;
//        if (leftMOre > 0) {
//            dfs(chars,index,left+1,right,leftMOre-1,rightMore);
//        }
//        if (rightMore > 0) {
//            dfs(chars,index,left,right+1,leftMOre,rightMore-1);
//        }
    }

    // 时间显示
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long seconds = scanner.nextLong();

        int oneDay = 24*60*60*1000;// ms
        while (seconds >= oneDay) {
            seconds -= oneDay;
        }
        seconds /= 1000;
        int hour = (int)seconds / 3600;
        seconds -= hour*3600;
        int min = (int)seconds / 60;
        seconds -= min*60;
        System.out.println( (hour>=10? hour : ("0"+hour)) + ":" +
                (min>=10? min : ("0"+min)) + ":" +
                (seconds>=10? seconds : ("0"+seconds)));
    }


    // 杨辉三角
    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long num = scanner.nextLong();
        List<Long> list1 = new ArrayList<>();
        List<Long> list2 = new ArrayList<>();
        list1.add(1l);
        int ret = 1;
        if (num == 1) {
            System.out.println(1);
            return;
        }
        for (int i = 1; ; i++) {
            list2.add(1l);
            ret++;
            for (int j = 1; j < i; j++) {
                list2.add(list1.get(j-1)+list1.get(j));
                ret++;
                if (list2.get(j) == num) {
                    System.out.print(ret);
                    return;
                }
                if (list2.get(j) > num) {
                    System.out.println(((1 + num) * num / 2) + 2);
                    return;
                }
            }
            list2.add(1l);
            ret++;
            list1 = list2;
            list2 = new ArrayList<>();
        }
    }
}